package com.taofuxn.yycreazy.adpater;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.taofuxn.yycreazy.R;
import com.taofuxn.yycreazy.adpater.base.TaofuRecyclerAdapter;
import com.taofuxn.yycreazy.adpater.base.TaofuRecyclerViewHodler;
import com.taofuxn.yycreazy.mvp.model.VchatBean;
import com.taofuxn.yycreazy.ui.activity.DisplayImgActivity;
import com.taofuxn.yycreazy.ui.activity.WebActivity;

import java.util.ArrayList;

/**
 * Created by taofuxn on 2016/9/24.
 */
public class VchatAdapter extends TaofuRecyclerAdapter<VchatBean.Result.VchatInfo> {
    public VchatAdapter(int layoutId, ArrayList<VchatBean.Result.VchatInfo> mDatas) {
        super(layoutId, mDatas);
    }

    @Override
    protected void convert(final TaofuRecyclerViewHodler holder, final VchatBean.Result.VchatInfo b) {
        if (!TextUtils.isEmpty(b.title))
            holder.setText(R.id.vc_title, b.title);

        if (!TextUtils.isEmpty(b.source))
            holder.setText(R.id.vc_source, "来源：" + b.source);

        if (!TextUtils.isEmpty(b.firstImg)) {
            holder.retrieveView(R.id.vc_img).setVisibility(View.VISIBLE);
            Glide.with(holder.itemView.getContext()).load(b.firstImg)
                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                    .into((ImageView) holder.retrieveView(R.id.vc_img));
            holder.retrieveView(R.id.vc_img).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(holder.itemView.getContext(), DisplayImgActivity.class);
                    intent.putExtra("url", b.firstImg);
                    holder.itemView.getContext().startActivity(intent);
                }
            });
        } else {
            holder.retrieveView(R.id.vc_img).setVisibility(View.GONE);
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!TextUtils.isEmpty(b.url)) {
                    Intent intent = new Intent(holder.itemView.getContext(), WebActivity.class);
                    intent.putExtra("url", b.url);
                    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    holder.itemView.getContext().startActivity(intent);
                }
            }
        });

    }
}
